<template>
    <el-row class="home" :gutter="20" style="padding-top: 20px">
        <el-card v-for="it in tableData">
            <div class="up-box">
                <div>
                    <i class="el-icon-s-management" style="padding-right: 10px"></i>
                    <a @click="enterQuestion(it)">{{it.name}}</a>
                </div>
                <div>
                    <el-alert
                            :title="(it.status == 0) ? '禁止' : (it.status == 1) ? '一直可用' : '启用'"
                            type="success"
                            :closable="false"
                            effect="dark">
                    </el-alert>
                </div>
            </div>

            <div class="down-box">
                <div>分数：<span>0</span></div>
                <div>
                    <i class="el-icon-user" style="padding-right: 10px"></i>
                    <span>{{it.author}}</span>
                </div>
            </div>
        </el-card>
    </el-row>
</template>

<script>
    //axios
    import axios from 'axios'


    export default {
        name: "",
        data(){
            return {
                tableData: [],
                score: [],  //获取题目集的分数
                status: '', //题目集状态
            }
        },
        methods: {
            enterQuestion(data){
                //获取题目集id
                var collectionId = data.id;
                //跳转到对应的题目页面
                this.$router.push({
                    path: '/admin/problem/manage',
                    query: {id: collectionId}
                })
            }
        },
        created: function () {
            //初始化表格数据
            //TODO 后面还需要修改，分为全部和我的
            //这里是查询条件
            let params = {};
            var that = this;
            let token = localStorage.getItem('token');

            //发送请求
            /*
                接口: 获取全部题目集
                请求地址: http://localhost:8881/producer/qcollection/select
                请求方法: post
                请求参数: 查询条件
                响应内容: 响应结果
            */
            axios({
                method: 'post',
                url: 'http://localhost:8881/producer/qcollection/select',
                data: params,
                headers: {
                    token: token
                }
            }).then(function (response) {
                var res = response.data;
                if(res.code == 200){
                    that.tableData = res.data.collectionList;
                }else{
                    that.$message.error('数据获取失败！');
                }
            }).catch(function (error) {
                console.log(error);
            });
        }
    }
</script>

<style scoped>
    .up-box, .down-box{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
</style>